package com.yhq.ojbackendjudgeservice.judge;


import com.yhq.ojbackendjudgeservice.judge.stratege.DefaultJudgeStrategy;
import com.yhq.ojbackendjudgeservice.judge.stratege.JavaLanguageJudgeStrategy;
import com.yhq.ojbackendjudgeservice.judge.stratege.JudgeContext;
import com.yhq.ojbackendjudgeservice.judge.stratege.JudgeStrategy;
import com.yhq.ojbackendmodel.model.codesandbox.JudgeInfo;
import com.yhq.ojbackendmodel.model.entity.QuestionSubmit;
import org.springframework.stereotype.Service;

/**
 * @program: oj-backend
 * @description: 用于判断使用哪个具体的JudgeStrategy
 * @author: HenryYang
 * @create: 2023-08-23 19:46
 **/
@Service
public class JudgeManager {

    /**
     * 执行判题
     *
     * @param judgeContext
     * @return
     */
    JudgeInfo doJudge(JudgeContext judgeContext) {
        QuestionSubmit questionSubmit = judgeContext.getQuestionSubmit();
        String language = questionSubmit.getLanguage();
        JudgeStrategy judgeStrategy = new DefaultJudgeStrategy();
        if ("java".equals(language)) {
            judgeStrategy = new JavaLanguageJudgeStrategy();
        }
        return judgeStrategy.doJudge(judgeContext);
    }

}